import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import MetaLayouts from "vite-plugin-vue-meta-layouts";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver, VantResolver } from "unplugin-vue-components/resolvers";
import AutoImport from "unplugin-auto-import/vite";
import Pages from "vite-plugin-pages";
import { dirResolver, DirResolverHelper } from "vite-auto-import-resolvers";
import { viteMockServe as Mock } from "vite-plugin-mock";

export default defineConfig({
  server: {
    https: false,
    port: 3002,//设置服务启动端口号
    host:'0.0.0.0',
    proxy: {
        '/webapi': {
            target: 'http://zzlcp.test/api.php', // 接口的域名
            // target: 'https://community.yjzx.com/', // 接口的域名
            secure: true, // 如果是https接口，需要配置这个参数
            changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
            rewrite: path => path.replace(/^\/webapi/, '')
        }
    }
  },
  // server: {
  //   https: false,
  //   port: 80,//设置服务启动端口号
  //   proxy: {
  //       '/webapi': {
  //           target: 'http://t.community.yjzx.com/', // 接口的域名
  //           secure: false, // 如果是https接口，需要配置这个参数
  //           changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
  //           // rewrite: path => path.replace(/^\/webapi/, 'api')
  //       }
  //   }
  // },
  plugins: [
    vue(),
    MetaLayouts(),
    Pages(),
    DirResolverHelper(),
    Components({
      resolvers: [ElementPlusResolver(), VantResolver()],
    }),
    AutoImport({
      imports: ["vue", "vue-router", "pinia"],
      resolvers: [
        dirResolver({
          target: "src/api", // 目标目录
        }),
        dirResolver({
          target: "src/mock", // 目标目录
        }),
        dirResolver({
          target: "src/stores", // 目标目录
          suffix: "Store", // 强制后缀为 Store
        }),
      ],
    }),
    // mock 服务
    Mock({
      mockPath: "src/mock",
      enable: true,
    }),
  ],
});
